# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.pro>

_realname=osgQt
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=3.5.7
pkgrel=9
pkgdesc="OpenSceneGraph Qt5 Modules (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
license=('spdx:LGPL-2.1')
url="https://github.com/openscenegraph/osgQt"
depends=("${MINGW_PACKAGE_PREFIX}-qt5-base"
         "${MINGW_PACKAGE_PREFIX}-OpenSceneGraph")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=(${_realname}-${pkgver}.tar.gz::https://github.com/openscenegraph/osgQt/archive/${pkgver}.tar.gz
        001-qt5-render-issue.patch
        002-osg-compatibility-old-version.patch
        003-cmake-bad-libs-parse.patch)
sha256sums=('dcc4436590639168e6470fe9c5343c82bca738d3296ebee014f40f2dc029afa1'
            'c0b2483583f0d1b8c8f828e953dfad8a5ae47453df86714a1caf091e5ba3f3d1'
            'c253e66e5153075e117c70e6014dee085ec7c6289b61505609b6912612a4c35b'
            '599283f2269f532faa22d160c0f65747c29333cf3bf2cd64e3f01ad6c6370a09')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-qt5-render-issue.patch
  patch -p1 -i ${srcdir}/002-osg-compatibility-old-version.patch
  patch -p1 -i ${srcdir}/003-cmake-bad-libs-parse.patch
}

build() {
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  declare -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    _extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  "${MINGW_PREFIX}"/bin/cmake.exe \
    -GNinja \
    -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
    "${_extra_config[@]}" \
    -DBUILD_OSG_EXAMPLES=ON \
    ../${_realname}-${pkgver}

  "${MINGW_PREFIX}"/bin/cmake --build .
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}

  DESTDIR=${pkgdir} "${MINGW_PREFIX}"/bin/cmake.exe --install .

  cp -f ${pkgdir}${MINGW_PREFIX}/lib/libosgQt{5,}${_dsuf}.dll.a
}
